/** Lachlan Hewson-Doherty (h201384171)
 *  Diploma of Digital and Interactive Games
 *  lachlan_doherty@live.com.au
 *  2013
 */

package cabbage.database.utilities;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseConnection {
	

	
	
	
	
	public Connection getConnection() {
		
		System.out.println
						("-------- MySQL JDBC Connection Testing ------------");
		

		Connection connection = null;
		
		
		String address = "jdbc:mysql://localhost:";
		
		String portNumber = "3306";
		
		String databaseName = "/cabbagedb";
		
		String username = "root";
		
		String password = "";
		
		String connectionString = address + portNumber + databaseName;
		
		

		try {
			
			Class.forName
					("com.mysql.jdbc.Driver");
			
			
		} catch (ClassNotFoundException e) {
			
			System.out.println
						("Where is your MySQL JDBC Driver?");
			
			e.printStackTrace
						();
			
			return connection;
			
		}
		

		System.out.println
					("MySQL JDBC Driver Registered!");


		try {
			
			connection = DriverManager
					.getConnection(connectionString,username,password);

		} catch (SQLException e) {
			
			System.out.println
						("Connection Failed! Check output console");
			
			e.printStackTrace
						();
			
			return connection;
			
		}
		

		if (connection != null) {
			
			System.out.println
					("You made it, take control of your database now!");
		
		
		} 
		
		
		else {
			
			System.out.println
						("Failed to make connection!");
			
		}
		

		return connection;
		

	}

}
